package com.tienon.message.mq;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.tienon.message.entity.Push_App;
import com.tienon.message.mapper.Push_AppMapper;

@Component
@Transactional
public class GetTenAppMsgsAndUpdateState {

	private static Logger log = Logger
			.getLogger(GetTenAppMsgsAndUpdateState.class);

	@Resource
	private Push_AppMapper appDao;

	public List<Push_App> getTenAppMsgsAndUpdateState() {

		List<Push_App> datas = appDao.findTenDatas();

		for (Push_App data : datas) {

			data.setState(2);
			data.setSendTime(new Date());
			data.setSendTimes(1);
			appDao.updateByPrimaryKeySelective(data);
			log.info("线程:" + Thread.currentThread().getName() + " 更新发送表状态:批次号:"
					+ data.getBatId() + " 流水号:" + data.getSerial() + " 发送序号:"
					+ data.getSplitId() + " 内容:" + data.getMsg() + " 消息的优先级:"
					+ data.getPrior() + " 发送次数:" + data.getSendTimes()
					+ " 发送时间:" + data.getSendTime() + " 更新发送表状态为:发送中(2)");
		}

//		try {
//			Thread.sleep(3000);
//		} catch (InterruptedException e) {
//		
//			e.printStackTrace();
//		}
		
		return datas;
	}

}
